package edu.wayne.cs.csc4110.hw6.plugins.example.meteor;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;

import edu.wayne.cs.csc4110.hw6.framework.Util.RandomUtil;

public class Meteor {
	private int radius;
	private Point center;
	private int xPath;
	private int yPath;
	private int speed;
	private boolean destroyed;

	public Meteor(int radius) {
		this.destroyed = false;
		this.radius = radius;
		this.speed = (int) (radius * 0.2);
		xPath = RandomUtil.nextInt(10, 800);
		yPath = 0;
		center = new Point(xPath, yPath);
	}

	public void update() {
		yPath += speed;
		center.setLocation(xPath, yPath);
	}

	public void draw(Graphics g) {
		if (!this.destroyed) {
			g.setColor(Color.GRAY);
			g.drawOval(center.x, center.y, radius, radius);
			g.setColor(Color.DARK_GRAY);
			g.fillOval(center.x, center.y, radius, radius);
		}

	}

	public boolean clickInCircle(Point p) {
		return Math.pow((p.getX() - center.getX()), 2)
				+ Math.pow((p.getY() - center.getY()), 2) < Math.pow(radius, 2);
	}

	public boolean checkCollision(int height) {
		if (yPath >= height - radius) {
			return true;
		}
		return false;
	}

	public int getDestructionValue() {
		return (int) (radius * .5);
	}

	public void destroy() {
		this.radius = 0;
		this.destroyed = true;
	}

}
